﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.Entity;   
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;
using QLGT.Models;
using System.Web.Script.Serialization;
using System.Data.OleDb;
using System.Data;
using System.Data.Entity.Validation;
using System.Text;


namespace QLGT.Controllers
{
    public class QLDanhMucController : Controller
    {
        QLGTContext db = new QLGTContext();

        // GET: QLDanhMuc
        #region QLChucVu
        public JsonResult LayChucVu()
        {
            return Json(db.tbl_ChucVu.ToList(), JsonRequestBehavior.AllowGet);
        }
        public ActionResult ChucVu()
        {
            if (!Request.IsAjaxRequest())
                return View();

            return PartialView();
        }
        public ActionResult HienThiChucVu([DataSourceRequest] DataSourceRequest request)
        {
            return Json(db.tbl_ChucVu.ToDataSourceResult(request));
        }

        //[ValidateAntiForgeryToken]
        public ActionResult TaoChucVu([DataSourceRequest] DataSourceRequest request, tbl_ChucVu data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.tbl_ChucVu.Add(data);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult SuaChucVu([DataSourceRequest] DataSourceRequest request, tbl_ChucVu data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.Entry(data).State = EntityState.Modified;
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult XoaChucVu([DataSourceRequest] DataSourceRequest request, tbl_ChucVu data)
        {
            if (data != null)
            {
                tbl_ChucVu itemdata = db.tbl_ChucVu.First(item => item.MaChucVu == data.MaChucVu);
                db.tbl_ChucVu.Remove(itemdata);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        #endregion

        #region QLHeDaoTao
        public JsonResult LayHeDaoTao()
        {
            return Json(db.tbl_HeDaoTao.ToList(), JsonRequestBehavior.AllowGet);
        }
        public ActionResult HeDaoTao()
        {
            if (!Request.IsAjaxRequest())
                return View();

            return PartialView();
        }
        public ActionResult HienThiHeDaoTao([DataSourceRequest] DataSourceRequest request)
        {
            return Json(db.tbl_HeDaoTao.ToDataSourceResult(request));
        }

        //[ValidateAntiForgeryToken]
        public ActionResult TaoHeDaoTao([DataSourceRequest] DataSourceRequest request, tbl_HeDaoTao data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.tbl_HeDaoTao.Add(data);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult SuaHeDaoTao([DataSourceRequest] DataSourceRequest request, tbl_HeDaoTao data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.Entry(data).State = EntityState.Modified;
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult XoaHeDaoTao([DataSourceRequest] DataSourceRequest request, tbl_HeDaoTao data)
        {
            if (data != null)
            {
                tbl_HeDaoTao itemdata = db.tbl_HeDaoTao.First(item => item.MaHeDaoTao == data.MaHeDaoTao);
                db.tbl_HeDaoTao.Remove(itemdata);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        #endregion

        #region QLHocHam
        public JsonResult LayHocHam()
        {
            return Json(db.tbl_HocHam.ToList(), JsonRequestBehavior.AllowGet);
        }
        public ActionResult HocHam()
        {
            if (!Request.IsAjaxRequest())
                return View();

            return PartialView();
        }
        public ActionResult HienThiHocHam([DataSourceRequest] DataSourceRequest request)
        {
            return Json(db.tbl_HocHam.ToDataSourceResult(request));
        }

        //[ValidateAntiForgeryToken]
        public ActionResult TaoHocHam([DataSourceRequest] DataSourceRequest request, tbl_HocHam data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.tbl_HocHam.Add(data);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult SuaHocHam([DataSourceRequest] DataSourceRequest request, tbl_HocHam data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.Entry(data).State = EntityState.Modified;
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult XoaHocHam([DataSourceRequest] DataSourceRequest request, tbl_HocHam data)
        {
            if (data != null)
            {
                tbl_HocHam itemdata = db.tbl_HocHam.First(item => item.MaHocHam == data.MaHocHam);
                db.tbl_HocHam.Remove(itemdata);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        #endregion

        #region QLHocVi
        public JsonResult LayHocVi()
        {
            return Json(db.tbl_HocVi.ToList(), JsonRequestBehavior.AllowGet);
        }
        public ActionResult HocVi()
        {
            if (!Request.IsAjaxRequest())
                return View();

            return PartialView();
        }
        public ActionResult HienThiHocVi([DataSourceRequest] DataSourceRequest request)
        {
            return Json(db.tbl_HocVi.ToDataSourceResult(request));
        }

        //[ValidateAntiForgeryToken]
        public ActionResult TaoHocVi([DataSourceRequest] DataSourceRequest request, tbl_HocVi data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.tbl_HocVi.Add(data);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult SuaHocVi([DataSourceRequest] DataSourceRequest request, tbl_HocVi data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.Entry(data).State = EntityState.Modified;
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult XoaHocVi([DataSourceRequest] DataSourceRequest request, tbl_HocVi data)
        {
            if (data != null)
            {
                tbl_HocVi itemdata = db.tbl_HocVi.First(item => item.MaHocVi == data.MaHocVi);
                db.tbl_HocVi.Remove(itemdata);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        #endregion

        #region QLKhoa
        public JsonResult LayKhoa()
        {
            return Json(db.tbl_Khoa.ToList(), JsonRequestBehavior.AllowGet);
        }
        public ActionResult Khoa()
        {
            if (!Request.IsAjaxRequest())
                return View();

            return PartialView();
        }
        public ActionResult HienThiKhoa([DataSourceRequest] DataSourceRequest request)
        {
            return Json(db.tbl_Khoa.ToDataSourceResult(request));
        }

        //[ValidateAntiForgeryToken]
        public ActionResult TaoKhoa([DataSourceRequest] DataSourceRequest request, tbl_Khoa data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.tbl_Khoa.Add(data);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult SuaKhoa([DataSourceRequest] DataSourceRequest request, tbl_Khoa data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.Entry(data).State = EntityState.Modified;
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult XoaKhoa([DataSourceRequest] DataSourceRequest request, tbl_Khoa data)
        {
            if (data != null)
            {
                tbl_Khoa itemdata = db.tbl_Khoa.First(item => item.MaKhoa == data.MaKhoa);
                db.tbl_Khoa.Remove(itemdata);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        #endregion

        #region QLNganh
        public JsonResult LayNganh()
        {
            return Json(db.tbl_Nganh.ToList(), JsonRequestBehavior.AllowGet);
        }
        public ActionResult Nganh()
        {
            if (!Request.IsAjaxRequest())
                return View();

            return PartialView();
        }
        public ActionResult HienThiNganh([DataSourceRequest] DataSourceRequest request)
        {
            return Json(db.tbl_Nganh.ToDataSourceResult(request));
        }

        //[ValidateAntiForgeryToken]
        public ActionResult TaoNganh([DataSourceRequest] DataSourceRequest request, tbl_Nganh data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.tbl_Nganh.Add(data);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult SuaNganh([DataSourceRequest] DataSourceRequest request, tbl_Nganh data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.Entry(data).State = EntityState.Modified;
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult XoaNganh([DataSourceRequest] DataSourceRequest request, tbl_Nganh data)
        {
            if (data != null)
            {
                tbl_Nganh itemdata = db.tbl_Nganh.First(item => item.MaNganh == data.MaNganh);
                db.tbl_Nganh.Remove(itemdata);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        #endregion

        #region QLNhaXuatBan
        public JsonResult LayNhaXuatBan()
        {
            return Json(db.tbl_NhaXuatBan.ToList(), JsonRequestBehavior.AllowGet);
        }
        public ActionResult NhaXuatBan()
        {
            if (!Request.IsAjaxRequest())
                return View();

            return PartialView();
        }
        public ActionResult HienThiNhaXuatBan([DataSourceRequest] DataSourceRequest request)
        {
            return Json(db.tbl_NhaXuatBan.ToDataSourceResult(request));
        }

        //[ValidateAntiForgeryToken]
        public ActionResult TaoNhaXuatBan([DataSourceRequest] DataSourceRequest request, tbl_NhaXuatBan data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.tbl_NhaXuatBan.Add(data);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult SuaNhaXuatBan([DataSourceRequest] DataSourceRequest request, tbl_NhaXuatBan data)
        {
            if (data != null && ModelState.IsValid)
            {
                db.Entry(data).State = EntityState.Modified;
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        public ActionResult XoaNhaXuatBan([DataSourceRequest] DataSourceRequest request, tbl_NhaXuatBan data)
        {
            if (data != null)
            {
                tbl_NhaXuatBan itemdata = db.tbl_NhaXuatBan.First(item => item.MaNXB == data.MaNXB);
                db.tbl_NhaXuatBan.Remove(itemdata);
                db.SaveChanges();
            }
            return Json(ModelState.ToDataSourceResult());
        }
        #endregion

        
    }
}